/*
PearReview - The peer review assistant.
Copyright (C) 2009  Dimitrij Pankratz, Anton Musichin
http://www.pearreview.com, info@pearreview.com

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

package com.pearreview.ui;

import java.awt.event.MouseEvent;
import java.io.File;

import javax.swing.Icon;
import javax.swing.JMenuItem;

public class FileMenuItem extends JMenuItem {
	private static final long serialVersionUID = 1212118304115396240L;
	private File file;
	private boolean mnemonicVisible = false;
	
	public FileMenuItem() {
		super();
		
		init();
	}
	
	public FileMenuItem(File file) {
		this();
		this.file = file;
		
		init();
	}
	
	public FileMenuItem(File file, int mnemonic) {
		this(file);
		this.setMnemonic(mnemonic);
		
		setMnemonicVisible(true);
		
		init();
	}

	public FileMenuItem(File file, Icon icon) {
		this(file);
		this.setIcon(icon);
		
		init();
	}
	
	public void setMnemonicVisible(boolean b) {
		mnemonicVisible = b;
		
		init();
	}
	
	public void init() {
		// ToolTipManager.sharedInstance().registerComponent(this);
	}
	
	public boolean isMnemonicVisible() {
		return mnemonicVisible;
	}
	
	public File getFile() {
		return file;
	}
	
	public void setFile(File file) {
		this.file = file;
	}
	
	@Override
	public String getToolTipText() {
		if(file != null) {
			return file.toString();
		}
		return super.getToolTipText();
	}
	
	@Override
	public String getToolTipText(MouseEvent event) {
		return getToolTipText();
	}
	
	@Override
	public String getText() {
		if(file != null) {
			if(isMnemonicVisible()) {
				return (char)getMnemonic() + " " + file.getName();
			}
			return file.getName();
		} else {
			return super.getText();
		}
	}
}
